// pages/dm/dm.js
Page({

        /**
         * 页面的初始数据
         */
        data: {
                addresslists: [{
                        id: 0,
                        name: "张三",
                        ttelephone: "13044445555",
                        address: "广东省广州市天河区珠吉路999号"
                }, {
                        id: 1,
                        name: "李四",
                        ttelephone: "13044445555",
                        address: "广东省广州市天河区珠吉路999号"
                }, {
                        id: 2,
                        name: "王五",
                        ttelephone: "13044445555",
                        address: "广东省广州市天河区珠吉路999号"
                }],
                num:0,
                id: 2,
                name: "",
                ttelephone: "",
                address: "",
                fase: false,
                index:null,
        },
       //修改地址
       modify(obj){
               let index = obj.currentTarget.dataset.index;
               this.data.num=1;
               console.log(this.data.num)
               this.data.index= index
               console.log(this.data.addresslists[index])
                this.setData({
                        fase:!this.data.fase,
                        num:this.data.num,
                        id:this.data.addresslists[index].id,
                        name:this.data.addresslists[index].name,
                        ttelephone:this.data.addresslists[index].ttelephone,
                        address:this.data.addresslists[index].address,
                        
                })
       },
        goPay(obj) {
                //获取index
                let index = obj.currentTarget.dataset.index
                //缓存地址
                wx.setStorageSync("addresslists", [this.data.addresslists[index]]);
                //返回上一个页面
                wx.navigateBack({
                        delta: 1
                })
        },

        //添加新地址
        fasebut() {
                this.setData({
                        fase: !this.data.fase
                });
        },
        //姓名
        name(e) {
                this.data.name = e.detail.value,
                console.log(this.data.name)
        },
        //电话
        ttelephone(e) {
                this.data.ttelephone = e.detail.value,
                console.log(this.data.ttelephone)
        },
        //地址
        address(e) {
                this.data.address = e.detail.value,
                console.log(this.data.address);
        },
        //保存新地址(){
        presebut() {
                this.data.addresslists.push({
                        id:this.data.id,
                        name:this.data.name,
                        ttelephone:this.data.ttelephone,
                        address:this.data.address,
                }),
                 console.log(this.data.addresslists);
                 this.data.id+=1
                 if(this.data.num==1){
                        this.data.addresslists.splice(this.data.index,1);
                        this.data.num=0
                 }
                this.setData({
                        fase: !this.data.fase,
                        num:this.data.num,
                        addresslists: this.data.addresslists,
                        id: this.data.id,
                        name: "",
                        ttelephone: "",
                        address: "",
                });
                console.log(this.data.id)
        },

        /**
         * 生命周期函数--监听页面加载
         */
        onLoad: function (options) {

        },

        /**
         * 生命周期函数--监听页面初次渲染完成
         */
        onReady: function () {

        },

        /**
         * 生命周期函数--监听页面显示
         */
        onShow: function () {

        },

        /**
         * 生命周期函数--监听页面隐藏
         */
        onHide: function () {

        },

        /**
         * 生命周期函数--监听页面卸载
         */
        onUnload: function () {

        },

        /**
         * 页面相关事件处理函数--监听用户下拉动作
         */
        onPullDownRefresh: function () {

        },

        /**
         * 页面上拉触底事件的处理函数
         */
        onReachBottom: function () {

        },

        /**
         * 用户点击右上角分享
         */
        onShareAppMessage: function () {

        }
})